<?php

// 获取计划报表
// GET pk10.planReport
// http://sg.io/api?pk10.planReport&start_date=2018-01-15&finsh_date=2018-01-18

namespace app\api\resource\pk10;
use think\Db;
use think\facade\Config;
use think\facade\Session;
use think\facade\Validate;
use app\api\lib\Page;

class PlanReport
{
    // 方法
    public $_method = ['GET'];
    // 前置
    public $_pre    = ['member'];
    // 描述
    public $_description = '获取计划报表';
    // 参数
    public $_param  = [
        'start_date' => '开始日期',
        'finsh_date' => '截止日期',
    ];

    public function run(&$request)
    {
        $startDate = $request->param('start_date/s','','trim');
        $finshDate = $request->param('finsh_date/s','','trim');

        if ( !Validate::dateFormat($startDate,'Y-m-d') ) return [422,'开始日期必须'];
        if ( !Validate::dateFormat($finshDate,'Y-m-d') ) return [422,'截止日期必须'];

        $sTime = strtotime( date($startDate . ' 00:00:00') );
        $eTime = strtotime( date($finshDate . ' 23:59:59') );
        $list  = Db::name('plan')->where('v1_loc','>',0)
                                 ->where('create_time','>',$sTime)
                                 ->where('create_time','<',$eTime)
                                 ->field('no,v1_loc,v2_loc,v3_loc,v4_loc,v5_loc')
                                 ->order('no ASC')
                                 ->select();
        // p($list);die;

        $item = [
            'num' => count($list),
            'v1'  => [
                'c3'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c4'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c5'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c6'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
            ],
            'v2'  => [
                'c3'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c4'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c5'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c6'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
            ],
            'v3'  => [
                'c3'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c4'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c5'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c6'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
            ],
            'v4'  => [
                'c3'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c4'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c5'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c6'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
            ],
            'v5'  => [
                'c3'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c4'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c5'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c6'  => [
                    'win'     => 0,
                    'mis'     => 0,
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
            ],
        ];
        // p($item);die;

        $temp = [
            'v1' => [
                'c3' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c4' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c5' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c6' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
            ],
            'v2' => [
                'c3' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c4' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c5' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c6' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
            ],
            'v3' => [
                'c3' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c4' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c5' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c6' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
            ],
            'v4' => [
                'c3' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c4' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c5' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c6' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
            ],
            'v5' => [
                'c3' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c4' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c5' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
                'c6' => [
                    'max_win' => 0,
                    'max_mis' => 0,
                ],
            ],
        ];

        foreach ($list as $key => $val) {
            $item['v1']['c3']['win'] += ($val['v1_loc'] <= 3) ? 1 : 0;
            $item['v1']['c4']['win'] += ($val['v1_loc'] <= 4) ? 1 : 0;
            $item['v1']['c5']['win'] += ($val['v1_loc'] <= 5) ? 1 : 0;
            $item['v1']['c6']['win'] += ($val['v1_loc'] <= 6) ? 1 : 0;
            // ----------------------------------------------------------------------------------
            $vTemp = [ 'win'=>$temp['v1']['c3']['max_win'],'mis'=>$temp['v1']['c3']['max_mis'] ];
            $vItem = [ 'win'=>$item['v1']['c3']['max_win'],'mis'=>$item['v1']['c3']['max_mis'] ];
            $arr   = $this->_calcMax(3,$val['v1_loc'],$vTemp,$vItem);
            $temp['v1']['c3']['max_win'] = $arr[0]['win'];
            $temp['v1']['c3']['max_mis'] = $arr[0]['mis'];
            $item['v1']['c3']['max_win'] = $arr[1]['win'];
            $item['v1']['c3']['max_mis'] = $arr[1]['mis'];
            // ----------------------------------------------------------------------------------
            $vTemp = [ 'win'=>$temp['v1']['c4']['max_win'],'mis'=>$temp['v1']['c4']['max_mis'] ];
            $vItem = [ 'win'=>$item['v1']['c4']['max_win'],'mis'=>$item['v1']['c4']['max_mis'] ];
            $arr   = $this->_calcMax(4,$val['v1_loc'],$vTemp,$vItem);
            $temp['v1']['c4']['max_win'] = $arr[0]['win'];
            $temp['v1']['c4']['max_mis'] = $arr[0]['mis'];
            $item['v1']['c4']['max_win'] = $arr[1]['win'];
            $item['v1']['c4']['max_mis'] = $arr[1]['mis'];
            // ----------------------------------------------------------------------------------
            $vItem = [ 'win'=>$item['v1']['c5']['max_win'],'mis'=>$item['v1']['c5']['max_mis'] ];
            $vTemp = [ 'win'=>$temp['v1']['c5']['max_win'],'mis'=>$temp['v1']['c5']['max_mis'] ];
            $arr   = $this->_calcMax(5,$val['v1_loc'],$vTemp,$vItem);
            $temp['v1']['c5']['max_win'] = $arr[0]['win'];
            $temp['v1']['c5']['max_mis'] = $arr[0]['mis'];
            $item['v1']['c5']['max_win'] = $arr[1]['win'];
            $item['v1']['c5']['max_mis'] = $arr[1]['mis'];
            // ----------------------------------------------------------------------------------
            $vTemp = [ 'win'=>$temp['v1']['c6']['max_win'],'mis'=>$temp['v1']['c6']['max_mis'] ];
            $vItem = [ 'win'=>$item['v1']['c6']['max_win'],'mis'=>$item['v1']['c6']['max_mis'] ];
            $arr   = $this->_calcMax(6,$val['v1_loc'],$vTemp,$vItem);
            $temp['v1']['c6']['max_win'] = $arr[0]['win'];
            $temp['v1']['c6']['max_mis'] = $arr[0]['mis'];
            $item['v1']['c6']['max_win'] = $arr[1]['win'];
            $item['v1']['c6']['max_mis'] = $arr[1]['mis'];

            // ==================================================================================

            $item['v2']['c3']['win'] += ($val['v2_loc'] <= 3) ? 1 : 0;
            $item['v2']['c4']['win'] += ($val['v2_loc'] <= 4) ? 1 : 0;
            $item['v2']['c5']['win'] += ($val['v2_loc'] <= 5) ? 1 : 0;
            $item['v2']['c6']['win'] += ($val['v2_loc'] <= 6) ? 1 : 0;
            // ----------------------------------------------------------------------------------
            $vTemp = [ 'win'=>$temp['v2']['c3']['max_win'],'mis'=>$temp['v2']['c3']['max_mis'] ];
            $vItem = [ 'win'=>$item['v2']['c3']['max_win'],'mis'=>$item['v2']['c3']['max_mis'] ];
            $arr   = $this->_calcMax(3,$val['v2_loc'],$vTemp,$vItem);
            $temp['v2']['c3']['max_win'] = $arr[0]['win'];
            $temp['v2']['c3']['max_mis'] = $arr[0]['mis'];
            $item['v2']['c3']['max_win'] = $arr[1]['win'];
            $item['v2']['c3']['max_mis'] = $arr[1]['mis'];
            // ----------------------------------------------------------------------------------
            $vTemp = [ 'win'=>$temp['v2']['c4']['max_win'],'mis'=>$temp['v2']['c4']['max_mis'] ];
            $vItem = [ 'win'=>$item['v2']['c4']['max_win'],'mis'=>$item['v2']['c4']['max_mis'] ];
            $arr   = $this->_calcMax(4,$val['v2_loc'],$vTemp,$vItem);
            $temp['v2']['c4']['max_win'] = $arr[0]['win'];
            $temp['v2']['c4']['max_mis'] = $arr[0]['mis'];
            $item['v2']['c4']['max_win'] = $arr[1]['win'];
            $item['v2']['c4']['max_mis'] = $arr[1]['mis'];
            // ----------------------------------------------------------------------------------
            $vItem = [ 'win'=>$item['v2']['c5']['max_win'],'mis'=>$item['v2']['c5']['max_mis'] ];
            $vTemp = [ 'win'=>$temp['v2']['c5']['max_win'],'mis'=>$temp['v2']['c5']['max_mis'] ];
            $arr   = $this->_calcMax(5,$val['v2_loc'],$vTemp,$vItem);
            $temp['v2']['c5']['max_win'] = $arr[0]['win'];
            $temp['v2']['c5']['max_mis'] = $arr[0]['mis'];
            $item['v2']['c5']['max_win'] = $arr[1]['win'];
            $item['v2']['c5']['max_mis'] = $arr[1]['mis'];
            // ----------------------------------------------------------------------------------
            $vTemp = [ 'win'=>$temp['v2']['c6']['max_win'],'mis'=>$temp['v2']['c6']['max_mis'] ];
            $vItem = [ 'win'=>$item['v2']['c6']['max_win'],'mis'=>$item['v2']['c6']['max_mis'] ];
            $arr   = $this->_calcMax(6,$val['v2_loc'],$vTemp,$vItem);
            $temp['v2']['c6']['max_win'] = $arr[0]['win'];
            $temp['v2']['c6']['max_mis'] = $arr[0]['mis'];
            $item['v2']['c6']['max_win'] = $arr[1]['win'];
            $item['v2']['c6']['max_mis'] = $arr[1]['mis'];

            // ==================================================================================

            $item['v3']['c3']['win'] += ($val['v3_loc'] <= 3) ? 1 : 0;
            $item['v3']['c4']['win'] += ($val['v3_loc'] <= 4) ? 1 : 0;
            $item['v3']['c5']['win'] += ($val['v3_loc'] <= 5) ? 1 : 0;
            $item['v3']['c6']['win'] += ($val['v3_loc'] <= 6) ? 1 : 0;
            // ----------------------------------------------------------------------------------
            $vTemp = [ 'win'=>$temp['v3']['c3']['max_win'],'mis'=>$temp['v3']['c3']['max_mis'] ];
            $vItem = [ 'win'=>$item['v3']['c3']['max_win'],'mis'=>$item['v3']['c3']['max_mis'] ];
            $arr   = $this->_calcMax(3,$val['v3_loc'],$vTemp,$vItem);
            $temp['v3']['c3']['max_win'] = $arr[0]['win'];
            $temp['v3']['c3']['max_mis'] = $arr[0]['mis'];
            $item['v3']['c3']['max_win'] = $arr[1]['win'];
            $item['v3']['c3']['max_mis'] = $arr[1]['mis'];
            // ----------------------------------------------------------------------------------
            $vTemp = [ 'win'=>$temp['v3']['c4']['max_win'],'mis'=>$temp['v3']['c4']['max_mis'] ];
            $vItem = [ 'win'=>$item['v3']['c4']['max_win'],'mis'=>$item['v3']['c4']['max_mis'] ];
            $arr   = $this->_calcMax(4,$val['v3_loc'],$vTemp,$vItem);
            $temp['v3']['c4']['max_win'] = $arr[0]['win'];
            $temp['v3']['c4']['max_mis'] = $arr[0]['mis'];
            $item['v3']['c4']['max_win'] = $arr[1]['win'];
            $item['v3']['c4']['max_mis'] = $arr[1]['mis'];
            // ----------------------------------------------------------------------------------
            $vItem = [ 'win'=>$item['v3']['c5']['max_win'],'mis'=>$item['v3']['c5']['max_mis'] ];
            $vTemp = [ 'win'=>$temp['v3']['c5']['max_win'],'mis'=>$temp['v3']['c5']['max_mis'] ];
            $arr   = $this->_calcMax(5,$val['v3_loc'],$vTemp,$vItem);
            $temp['v3']['c5']['max_win'] = $arr[0]['win'];
            $temp['v3']['c5']['max_mis'] = $arr[0]['mis'];
            $item['v3']['c5']['max_win'] = $arr[1]['win'];
            $item['v3']['c5']['max_mis'] = $arr[1]['mis'];
            // ----------------------------------------------------------------------------------
            $vTemp = [ 'win'=>$temp['v3']['c6']['max_win'],'mis'=>$temp['v3']['c6']['max_mis'] ];
            $vItem = [ 'win'=>$item['v3']['c6']['max_win'],'mis'=>$item['v3']['c6']['max_mis'] ];
            $arr   = $this->_calcMax(6,$val['v3_loc'],$vTemp,$vItem);
            $temp['v3']['c6']['max_win'] = $arr[0]['win'];
            $temp['v3']['c6']['max_mis'] = $arr[0]['mis'];
            $item['v3']['c6']['max_win'] = $arr[1]['win'];
            $item['v3']['c6']['max_mis'] = $arr[1]['mis'];

            // ==================================================================================

            $item['v4']['c3']['win'] += ($val['v4_loc'] <= 3) ? 1 : 0;
            $item['v4']['c4']['win'] += ($val['v4_loc'] <= 4) ? 1 : 0;
            $item['v4']['c5']['win'] += ($val['v4_loc'] <= 5) ? 1 : 0;
            $item['v4']['c6']['win'] += ($val['v4_loc'] <= 6) ? 1 : 0;
            // ----------------------------------------------------------------------------------
            $vTemp = [ 'win'=>$temp['v4']['c3']['max_win'],'mis'=>$temp['v4']['c3']['max_mis'] ];
            $vItem = [ 'win'=>$item['v4']['c3']['max_win'],'mis'=>$item['v4']['c3']['max_mis'] ];
            $arr   = $this->_calcMax(3,$val['v4_loc'],$vTemp,$vItem);
            $temp['v4']['c3']['max_win'] = $arr[0]['win'];
            $temp['v4']['c3']['max_mis'] = $arr[0]['mis'];
            $item['v4']['c3']['max_win'] = $arr[1]['win'];
            $item['v4']['c3']['max_mis'] = $arr[1]['mis'];
            // ----------------------------------------------------------------------------------
            $vTemp = [ 'win'=>$temp['v4']['c4']['max_win'],'mis'=>$temp['v4']['c4']['max_mis'] ];
            $vItem = [ 'win'=>$item['v4']['c4']['max_win'],'mis'=>$item['v4']['c4']['max_mis'] ];
            $arr   = $this->_calcMax(4,$val['v4_loc'],$vTemp,$vItem);
            $temp['v4']['c4']['max_win'] = $arr[0]['win'];
            $temp['v4']['c4']['max_mis'] = $arr[0]['mis'];
            $item['v4']['c4']['max_win'] = $arr[1]['win'];
            $item['v4']['c4']['max_mis'] = $arr[1]['mis'];
            // ----------------------------------------------------------------------------------
            $vItem = [ 'win'=>$item['v4']['c5']['max_win'],'mis'=>$item['v4']['c5']['max_mis'] ];
            $vTemp = [ 'win'=>$temp['v4']['c5']['max_win'],'mis'=>$temp['v4']['c5']['max_mis'] ];
            $arr   = $this->_calcMax(5,$val['v4_loc'],$vTemp,$vItem);
            $temp['v4']['c5']['max_win'] = $arr[0]['win'];
            $temp['v4']['c5']['max_mis'] = $arr[0]['mis'];
            $item['v4']['c5']['max_win'] = $arr[1]['win'];
            $item['v4']['c5']['max_mis'] = $arr[1]['mis'];
            // ----------------------------------------------------------------------------------
            $vTemp = [ 'win'=>$temp['v4']['c6']['max_win'],'mis'=>$temp['v4']['c6']['max_mis'] ];
            $vItem = [ 'win'=>$item['v4']['c6']['max_win'],'mis'=>$item['v4']['c6']['max_mis'] ];
            $arr   = $this->_calcMax(6,$val['v4_loc'],$vTemp,$vItem);
            $temp['v4']['c6']['max_win'] = $arr[0]['win'];
            $temp['v4']['c6']['max_mis'] = $arr[0]['mis'];
            $item['v4']['c6']['max_win'] = $arr[1]['win'];
            $item['v4']['c6']['max_mis'] = $arr[1]['mis'];

            // ==================================================================================

            $item['v5']['c3']['win'] += ($val['v5_loc'] <= 3) ? 1 : 0;
            $item['v5']['c4']['win'] += ($val['v5_loc'] <= 4) ? 1 : 0;
            $item['v5']['c5']['win'] += ($val['v5_loc'] <= 5) ? 1 : 0;
            $item['v5']['c6']['win'] += ($val['v5_loc'] <= 6) ? 1 : 0;
            // ----------------------------------------------------------------------------------
            $vTemp = [ 'win'=>$temp['v5']['c3']['max_win'],'mis'=>$temp['v5']['c3']['max_mis'] ];
            $vItem = [ 'win'=>$item['v5']['c3']['max_win'],'mis'=>$item['v5']['c3']['max_mis'] ];
            $arr   = $this->_calcMax(3,$val['v5_loc'],$vTemp,$vItem);
            $temp['v5']['c3']['max_win'] = $arr[0]['win'];
            $temp['v5']['c3']['max_mis'] = $arr[0]['mis'];
            $item['v5']['c3']['max_win'] = $arr[1]['win'];
            $item['v5']['c3']['max_mis'] = $arr[1]['mis'];
            // ----------------------------------------------------------------------------------
            $vTemp = [ 'win'=>$temp['v5']['c4']['max_win'],'mis'=>$temp['v5']['c4']['max_mis'] ];
            $vItem = [ 'win'=>$item['v5']['c4']['max_win'],'mis'=>$item['v5']['c4']['max_mis'] ];
            $arr   = $this->_calcMax(4,$val['v5_loc'],$vTemp,$vItem);
            $temp['v5']['c4']['max_win'] = $arr[0]['win'];
            $temp['v5']['c4']['max_mis'] = $arr[0]['mis'];
            $item['v5']['c4']['max_win'] = $arr[1]['win'];
            $item['v5']['c4']['max_mis'] = $arr[1]['mis'];
            // ----------------------------------------------------------------------------------
            $vItem = [ 'win'=>$item['v5']['c5']['max_win'],'mis'=>$item['v5']['c5']['max_mis'] ];
            $vTemp = [ 'win'=>$temp['v5']['c5']['max_win'],'mis'=>$temp['v5']['c5']['max_mis'] ];
            $arr   = $this->_calcMax(5,$val['v5_loc'],$vTemp,$vItem);
            $temp['v5']['c5']['max_win'] = $arr[0]['win'];
            $temp['v5']['c5']['max_mis'] = $arr[0]['mis'];
            $item['v5']['c5']['max_win'] = $arr[1]['win'];
            $item['v5']['c5']['max_mis'] = $arr[1]['mis'];
            // ----------------------------------------------------------------------------------
            $vTemp = [ 'win'=>$temp['v5']['c6']['max_win'],'mis'=>$temp['v5']['c6']['max_mis'] ];
            $vItem = [ 'win'=>$item['v5']['c6']['max_win'],'mis'=>$item['v5']['c6']['max_mis'] ];
            $arr   = $this->_calcMax(6,$val['v5_loc'],$vTemp,$vItem);
            $temp['v5']['c6']['max_win'] = $arr[0]['win'];
            $temp['v5']['c6']['max_mis'] = $arr[0]['mis'];
            $item['v5']['c6']['max_win'] = $arr[1]['win'];
            $item['v5']['c6']['max_mis'] = $arr[1]['mis'];
        }

        $item['v1']['c3']['mis'] = $item['num'] - $item['v1']['c3']['win'];
        $item['v1']['c4']['mis'] = $item['num'] - $item['v1']['c4']['win'];
        $item['v1']['c5']['mis'] = $item['num'] - $item['v1']['c5']['win'];
        $item['v1']['c6']['mis'] = $item['num'] - $item['v1']['c6']['win'];
        // ----------------------------------------------------------------
        $item['v2']['c3']['mis'] = $item['num'] - $item['v2']['c3']['win'];
        $item['v2']['c4']['mis'] = $item['num'] - $item['v2']['c4']['win'];
        $item['v2']['c5']['mis'] = $item['num'] - $item['v2']['c5']['win'];
        $item['v2']['c6']['mis'] = $item['num'] - $item['v2']['c6']['win'];
        // ----------------------------------------------------------------
        $item['v3']['c3']['mis'] = $item['num'] - $item['v3']['c3']['win'];
        $item['v3']['c4']['mis'] = $item['num'] - $item['v3']['c4']['win'];
        $item['v3']['c5']['mis'] = $item['num'] - $item['v3']['c5']['win'];
        $item['v3']['c6']['mis'] = $item['num'] - $item['v3']['c6']['win'];
        // ----------------------------------------------------------------
        $item['v4']['c3']['mis'] = $item['num'] - $item['v4']['c3']['win'];
        $item['v4']['c4']['mis'] = $item['num'] - $item['v4']['c4']['win'];
        $item['v4']['c5']['mis'] = $item['num'] - $item['v4']['c5']['win'];
        $item['v4']['c6']['mis'] = $item['num'] - $item['v4']['c6']['win'];
        // ----------------------------------------------------------------
        $item['v5']['c3']['mis'] = $item['num'] - $item['v5']['c3']['win'];
        $item['v5']['c4']['mis'] = $item['num'] - $item['v5']['c4']['win'];
        $item['v5']['c5']['mis'] = $item['num'] - $item['v5']['c5']['win'];
        $item['v5']['c6']['mis'] = $item['num'] - $item['v5']['c6']['win'];

        // p($item);die;

        $member   = Session::get('member');
        $defAdmin = Config::get('sg.def_admin');
        if ( !in_array($member['mobile'],$defAdmin) ) {
            unset(
                  // v1
                  $item['v1']['c3']['max_win'],
                  $item['v1']['c4']['max_win'],
                  $item['v1']['c5']['max_win'],
                  $item['v1']['c6']['max_win'],
                  $item['v1']['c3']['max_mis'],
                  $item['v1']['c4']['max_mis'],
                  $item['v1']['c5']['max_mis'],
                  $item['v1']['c6']['max_mis'],
                  // v2
                  $item['v2']['c3']['max_win'],
                  $item['v2']['c4']['max_win'],
                  $item['v2']['c5']['max_win'],
                  $item['v2']['c6']['max_win'],
                  $item['v2']['c3']['max_mis'],
                  $item['v2']['c4']['max_mis'],
                  $item['v2']['c5']['max_mis'],
                  $item['v2']['c6']['max_mis'],
                  // v3
                  $item['v3']['c3']['max_win'],
                  $item['v3']['c4']['max_win'],
                  $item['v3']['c5']['max_win'],
                  $item['v3']['c6']['max_win'],
                  $item['v3']['c3']['max_mis'],
                  $item['v3']['c4']['max_mis'],
                  $item['v3']['c5']['max_mis'],
                  $item['v3']['c6']['max_mis'],
                  // v4
                  $item['v4']['c3']['max_win'],
                  $item['v4']['c4']['max_win'],
                  $item['v4']['c5']['max_win'],
                  $item['v4']['c6']['max_win'],
                  $item['v4']['c3']['max_mis'],
                  $item['v4']['c4']['max_mis'],
                  $item['v4']['c5']['max_mis'],
                  $item['v4']['c6']['max_mis'],
                  // v5
                  $item['v5']['c3']['max_win'],
                  $item['v5']['c4']['max_win'],
                  $item['v5']['c5']['max_win'],
                  $item['v5']['c6']['max_win'],
                  $item['v5']['c3']['max_mis'],
                  $item['v5']['c4']['max_mis'],
                  $item['v5']['c5']['max_mis'],
                  $item['v5']['c6']['max_mis']
                 );
        }

        // p($item);die;

        return [200,$item];
    }

    private function _calcMax($v, $loc, $temp, $item)
    {
        if ($loc <= $v) {
            $temp['win'] += 1;
            $item['win'] = ($item['win'] > $temp['win']) ? $item['win'] : $temp['win'];
            // ------------------------------------------------------------------------
            $temp['mis'] = 0;
        } else {
            $temp['mis'] += 1;
            $item['mis'] = ($item['mis'] > $temp['mis']) ? $item['mis'] : $temp['mis'];
            // ------------------------------------------------------------------------
            $temp['win'] = 0;
        }
        // p($loc);p('<=');p($v);p($temp);p($item);

        return [$temp,$item];
    }
}
